﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject;
using Meraz.Core.Repositories;
using Meraz.Core.Model;

namespace Meraz.Core.Commands
{
    public interface ISaveLinkCommand {
        ILinkRepository LinkRepository { get; set; }
        Link Execute(int postID, Url url, ToneType toneType);
    }
    public class SaveLinkCommand : BaseCommand, ISaveLinkCommand
    {
        [Inject]
        public ILinkRepository LinkRepository { get; set; }

        public Link Execute(int postID, Url url, ToneType toneType)
        {
            Link link = LinkRepository.GetByHref(postID, url.Name);
            if (link == null){
                link = new Link();
                LinkRepository.Add(link);
                link.PostID = postID;
                link.Url = url;
            }
            link.ToneType = toneType;
            Commit();
            return link;
        }
    }
}
